package bz.yfw.example.s3blazeds.part2.helper
{
	import bz.yfw.example.s3blazeds.part2.model.view.EmpViewModel;
	import bz.yfw.example.s3blazeds.part2.view.EmpEditThirdView;
	
	import org.seasar.akabana.yui.framework.ns.viewpart;
	
	import spark.components.Label;
	import spark.components.RadioButton;
	import spark.components.RadioButtonGroup;
	import spark.components.TextInput;
	import spark.components.supportClasses.ViewReturnObject;
	
	use namespace viewpart;

	/**
	 * 社員編集3初期処理Helper
	 * @author tokufxug http://twitter.com/tokufxug
	 */ 
	public class EmpEditThirdInitHelper
	{
		public var view:EmpEditThirdView;
		
		viewpart var txtinptEnterCompanyY:TextInput;
		
		viewpart var txtinptEnterCompanyM:TextInput;
		
		viewpart var txtinptEnterCompanyD:TextInput;
		
		viewpart var rdbStaff:RadioButton;
		
		viewpart var rdbChief:RadioButton;
		
		viewpart var rdbManager:RadioButton;
		
		viewpart var rdbGManager:RadioButton;
		
		viewpart var rdbgrpPosition:RadioButtonGroup;
		
		public function get empViewModel():EmpViewModel {
			var retObj:ViewReturnObject = view.navigator.poppedViewReturnedObject;
			
			if (retObj && retObj.object) {
				return retObj.object as EmpViewModel;
			}
			
			if (view.data && view.data is EmpViewModel) {
				return view.data as EmpViewModel;
			}
			return null;
		}
		
		public function reflectEmpModel():void {
			var vm:EmpViewModel = empViewModel;
			if (!vm) {
				return;
			}
			txtinptEnterCompanyY.text = vm.enterCompanyY;
			txtinptEnterCompanyM.text = vm.enterCompanyM;
			txtinptEnterCompanyD.text = vm.enterCompanyD;
			rdbgrpPosition.selectedValue = vm.position;
			
			view.viewModel = vm;
		}
		
		public function initPosition():void {
			rdbStaff.group = rdbChief.group 
				= rdbManager.group = rdbGManager.group = rdbgrpPosition;
		}
	}
}